package com.ysq.www.common.utils.token;

import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSONObject;
import com.ysq.www.api.user.entity.WxConfig;
import com.ysq.www.api.user.service.IWxConfigService;
import com.ysq.www.common.utils.RedisUtil;
import com.ysq.www.common.utils.message.HttpClientUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.io.IOException;


@Slf4j
@Component
@Order(value = 1)
public class StartService implements ApplicationRunner {

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private IWxConfigService wxConfigService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println("启动成功。。。。。。。。。。。。。。。。。。。");
        System.out.println("启动成功。。。。。。。。。。。。。。。。。。。");
        System.out.println("启动成功。。。。。。。。。。。。。。。。。。。");
        System.out.println("启动成功。。。。。。。。。。。。。。。。。。。");
        /*WxConfig wx = wxConfigService.getById(1);
        try {
            JSONObject js = HttpClientUtils.getAccessToken(wx.getAppId(), wx.getAppSecret());
            String accessToken = js.getString("access_token");
            if (StringUtils.isEmpty(accessToken)){
                int errCode = js.getIntValue("errcode");
                log.info("获取小程序全局Token失败，错误码:"+errCode);
            }
            log.info("获取小程序全局token成功!token:"+accessToken);
            redisUtil.set("accessToken",accessToken);
        } catch (IOException e) {
            log.error("获取access_token失败!");
            e.printStackTrace();
            return;
        }*/
    }
}
